<html>
<head><meta charset="utf-8"><title>Performance regressions when writing through pointers · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Performance.20regressions.20when.20writing.20through.20pointers.html">Performance regressions when writing through pointers</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="210061625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Performance%20regressions%20when%20writing%20through%20pointers/near/210061625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Tyson Nottingham <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Performance.20regressions.20when.20writing.20through.20pointers.html#210061625">(Sep 14 2020 at 20:52)</a>:</h4>
<p>I'm running into performance regressions when replacing something like:</p>
<div class="codehilite"><pre><span></span><code>self.buf = [0; BUFFER_SIZE];
</code></pre></div>


<p>with something like:</p>
<div class="codehilite"><pre><span></span><code>ptr::write_bytes(self.buf.as_mut_ptr(), 0, BUFFER_SIZE);
</code></pre></div>


<p>I don't need the write to be through a pointer here, but sometimes it's what you want. In general, I'm seeing regressions when replacing assignments with writes through pointers, even though the assembly for the containing function is exactly the same. I'm wondering if getting pointers involved is tripping up aliasing analysis in the context of inlining.</p>
<p>The problem doesn't occur when I compile the code in isolation. But when compile it inside a larger program (rustc, actually), I think that the compiler makes different decisions with respect to inlining. It doesn't make much sense to me, because the function with this write isn't ever inlined anyway. It's the functions that _call_ it that get inlined a different number of times depending on how I do the write.</p>
<p>Does anyone have insight as to what is going on? Or can at least point me to the area of the compiler that might be responsible?</p>



<a name="210062160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Performance%20regressions%20when%20writing%20through%20pointers/near/210062160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Performance.20regressions.20when.20writing.20through.20pointers.html#210062160">(Sep 14 2020 at 20:56)</a>:</h4>
<p>LLVM decides to inline things AFAIK</p>



<a name="210062173"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Performance%20regressions%20when%20writing%20through%20pointers/near/210062173" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Performance.20regressions.20when.20writing.20through.20pointers.html#210062173">(Sep 14 2020 at 20:56)</a>:</h4>
<p>Not sure where in llvm to look</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>